#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# @Time: 2019/4/12  17:43
# @Author: 余浪人
# @email: yulangren520@gmail.com


from apps.models import db, BaseModel
from apps.models.column_model import Column_model


class Document_Model(BaseModel):
    title = db.Column(db.String(255),comment='标题')
    superior = db.Column(db.Integer, db.ForeignKey(Column_model.id), comment='所属栏目')
    content = db.Column(db.Text, comment='内容')
    download1 = db.Column(db.Text, comment='下载地址1')
    download2 = db.Column(db.Text, comment='下载地址2')
    thumb_img = db.Column(db.Text, comment='缩略图片地址')
    clicks = db.Column(db.Integer, default=0, comment='点击数')
    author = db.Column(db.String(64),default='佚名', comment='作者')
    keyword = db.Column(db.String(256), comment='关键词')
    description = db.Column(db.String(512), comment='描述')
    source = db.Column(db.String(128), comment='来源')
    promulgator = db.Column(db.String(64), comment='发布者')
    contributor = db.Column(db.String(64), comment='投稿者')
    permissions = db.Column(db.Integer, default=0, comment='访问权限 |0 开放 | 1 一级会员 |2 二级会员')
    is_focus = db.Column(db.Boolean, default=0, comment='是否焦点图 | 0 否(默认) | 1 是')
    is_roll = db.Column(db.Boolean, default=0, comment='是否滚动图 | 0 否(默认) | 1 是')
    is_roll_text = db.Column(db.Boolean, default=0, comment='是否滚动文字 | 0 否(默认) | 1 是')
    is_index_stick = db.Column(db.Boolean, default=0, comment='是否首页置顶 | 0 否(默认) | 1 是')
    is_list_stick = db.Column(db.Boolean, default=0, comment='是否列表页置顶 | 0 否(默认) | 1 是')
    is_recommend = db.Column(db.Boolean, default=0, comment='是否推荐 | 0 否(默认) | 1 是')
    is_pass = db.Column(db.Boolean, default=1, comment='是否通过 | 0 否 | 1 是(默认)')
    weight = db.Column(db.Integer, default=0, comment='权重 | 0 默认 |越大越靠前')
    pro = db.relationship('Column_model', backref='document_model')

    def __repr__(self):
        return f'内容标题: <{self.title}>'

    def keys(self):
        return "title", "superior", "content", "download1", "download2", "thumb_img", "clicks", "author", "keyword", "description", "source", "promulgator", "contributor", "permissions", "is_focus", "is_roll", "is_roll_text", "is_index_stick", "is_list_stick", "is_recommend", "is_pass", "weight","update_time"
